﻿using System;
using Microsoft.Practices.ObjectBuilder;
using DataContracts;
using System.Web.UI.WebControls;
using System.Collections.Generic;

namespace TrainingWorkshop.MVPWebsite.Authority.Views
{
    public partial class CreateNewAuthority : Microsoft.Practices.CompositeWeb.Web.UI.Page, ICreateNewAuthorityView
    {
        private CreateNewAuthorityPresenter _presenter;

        #region Property

        public int AuthorityId { get; set; }

        public string AuthorityName
        {
            get
            {
                return this.txtAuthorityName.Text.ToString().Trim();
            }
        }
        public int LevelId
        {
            get
            {
                return Convert.ToInt32(this.ddlLevel.SelectedValue);
            }
        }
        public string LevelName
        {
            get
            {
                return this.ddlLevel.SelectedItem.Text.ToString().Trim();
            }
        }

        public IList<AuthorityLevelDTO> AuthorityLevelList
        {
            set
            {
                this.ddlLevel.DataSource = value;
                this.ddlLevel.DataTextField = "LevelName";
                this.ddlLevel.DataValueField = "LevelId";
                this.ddlLevel.DataBind();
                ddlLevel.Items.Insert(0, new ListItem("Please selected", "0"));
            }
        }

        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            if (this.IsPostBack == false)
            {
                _presenter.OnViewInitialized();
            }
            _presenter.OnViewLoaded();
        }

        [CreateNew]
        public CreateNewAuthorityPresenter Presenter
        {
            get
            {
                return this._presenter;
            }
            set
            {
                if (value == null)
                    throw new ArgumentNullException("value");

                this._presenter = value;
                this._presenter.View = this;
            }
        }

        protected void NewButton_Click(object sender, EventArgs e)
        {
            this._presenter.AddNewAuthority();

        }
        public void Redirect(string url)
        {
            Response.Redirect(url);
        }
	}
}

